package simtester.server

import grails.test.mixin.TestFor
import org.junit.Test

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(User)
class UserTests {

    @Test
    void createUserThatAlreadyExists() {
        def existingUser = new User(username: 'Linh', password: 'password')
        mockForConstraintsTests(User, [existingUser])

        def newUser = new User(username: 'Linh', password: 'pass')
        assert !newUser.validate()
        assert 'unique' == newUser.errors['username']
    }
    
    @Test
    void createUserWithoutRequiredFields() {
        def user = new User()
        assert !user.validate()
        assert 'nullable' in user.errors['username'].codes
        assert 'nullable' in user.errors['password'].codes
    }
    
    @Test
    void createUserSuccessfully() {
        def team = new Team(name: 'svt')
        def user = new User(username: 'Linh', password: 'pass', team: team)
        assert user.validate()
    }
}
